<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
		<title>
		</title>
		<script type="text/javascript" src="./Public/jquery-1.8.2.min.js"></script>		
		<link rel="stylesheet" href="./Public/Bootstrap/Css/bootstrap.min.css" />
		<link rel="stylesheet" href="Public/uploadify/uploadify.css" />
		<script type="text/javascript" src="./Public/uploadify/jquery.uploadify.min.js"></script>
		<!--载入百度编辑器-->
		<script type="text/javascript" charset="utf-8"src="Public/ueditor1_4_3/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8"src="Public/ueditor1_4_3/ueditor.all.min.js"></script>
		<script type="text/javascript" charset="utf-8"src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
		<script type="text/javascript">$(function() {
	$('[name=classify_cid]').change(function() {
			var tid = $('option:selected').attr('tid');
			$.ajax({
				type: "post",
				url: "{{U('getTypeAttr')}}",
				data: {
					id: tid
				},
				dataType: 'json',
				success: function(phpData) {
					//规格(可选)
					var spec = '';
					//属性（不可选）
					var attr = '';
					$.each(phpData, function(k, v) {
						//规格
						if (v.natype == 1) {
							spec += '<tr class="info">' +
								'<td>' + v.naname + '</td>' +
								'<td>' +
								'<select name="spec[' + v.nid + '][value][]" id=""><option value="">请选择</option>';
							$.each(v.nazhi, function(kk, vv) {
								spec += '<option value="' + vv + '">' + vv + '</option>';
							});
							spec += '</select></td><td>附加价格：<input type="text" name="spec[' + v.nid + '][price][]" id="" /></td>' +
								'<td><span class="btn btn-success add-spec">增加规格</span></td></tr>';
						} else { //属性
							attr += '<tr class="info">' +
								'<td>' + v.naname + '</td>' +
								'<td>' +
								'<select name="attr[' + v.nid + ']" id=""><option value="">请选择</option>';
							$.each(v.nazhi, function(kk, vv) {
								attr += '<option value="' + vv + '">' + vv + '</option>';
							});
							attr += '</select></td></tr>';
						}
					});
					//插入属性
					$('#attr').html(attr);
					$('#spec').html(spec);
					$('#ggt').val(tid);
				}
			});
		})
		//点击添加规格
	$('.add-spec').live('click', function() {
			//找到父级的tr
			var parentsTr = $(this).parents('tr');
			//把父级的tr克隆复制
			var cloneTr = parentsTr.clone();
			cloneTr.find('.add-spec').removeClass('add-spec btn-success').addClass('remove-spec btn-danger').html('删除规格');
			//插入下一行
			parentsTr.after(cloneTr);
		})
		//删除规格
	$('.remove-spec').live('click', function() {
		$(this).parents('tr').remove();
	})
})</script>
		<style type="text/css">/*去掉uploadify上传按钮的边框*/

.uploadify-button {
	background-color: transparent;
	border: none;
	padding: 0;
}

.uploadify:hover .uploadify-button {
	background-color: transparent;
}

.hide {
	display: none;
}

body {
	margin-bottom: 100px;
}</style>
	</head>
	<body>
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<form action="" method='post'>
						<fieldset>
							<legend>
								修改商品
							</legend>
							<table class='table table-bordered table-hover'>
								<thead>
									<tr>
										<th colspan="2" class="btn btn-primary">
											基本信息
										</th>
									</tr>
								</thead>
								<tbody>
									<tr class="info">
										<td>
											所属分类
										</td>
										<td>
											<select name="classify_cid">
												<option value="0">
													-请选择-
												</option>
												{{foreach from="$cdata" value="$v"}}
												<option value="{{$v['cid']}}" tid="{{$v['type_tid']}}" {{if value="$gdata['classify_cid']==$v['cid']"}} selected {{endif}}>
													{{$v['_name']}}
												</option>
												{{endforeach}}
											</select>
											<input id="ggt" type="hidden" name="type_tid" value="{{$olddata['type_tid']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											所属品牌
										</td>
										<td>
											<select name="brand_bid">
												<option value="0">
													-请选择-
												</option>
												<foreach name='brand' item='v'>
													{{foreach from="$bdata" value="$c"}}
													<option value="{{$c['bid']}}" {{if value="$gdata['brand_bid']==$c['bid']"}} selected {{endif}}>
														{{$c['bname']}}
													</option>
													{{endforeach}}
												</foreach>
											</select>
										</td>
									</tr>
									<tr class="info">
										<td>
											商品名称
										</td>
										<td>
											<input type="text" name='gname' value="{{$gdata['gname']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											市价场
										</td>
										<td>
											<input type="text" name='market' value="{{$gdata['market']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											商城价
										</td>
										<td>
											<input type="text" name='cheap' value="{{$gdata['cheap']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											库存
										</td>
										<td>
											<input type="text" name='repertory' value="{{$gdata['repertory']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											点击次数
										</td>
										<td>
											<input type="text" name='click' value="{{$gdata['click']}}"/>
										</td>
									</tr>
								</tbody>
							</table>
							<p class="btn btn-primary">
								商品属性
							</p>
							<table class="table table-bordered table-hover" id='attr' class="info">
								{{foreach from="$sdata" value="$v"}}
								{{if value="$v['natype']==0"}}
								<tr class="info">
									<td>{{$v['naname']}}</td>
									<td >
										<select name="attr[{{$v['nature_nid']}}]">
											{{foreach from="$v['nazhi']" value="$vv"}}
											<option value="{{$vv}}" {{if value="$vv==$v['nazhi']"}}selected{{endif}}>{{$vv}}</option>
											{{endforeach}}
										</select>
									</td>
								</tr>
								{{endif}}
								{{endforeach}}
							</table>		
				<p class="btn btn-primary">商品规格</p>
			<!--{{p($goodsattrData)}}-->
			<table class="table table-bordered table-hover" id="spec" style="border: 0px;">
				{{foreach from="$sdata" value="$v"}}
				{{if value="$v['natype']==1"}}
				<tr>
					<td>{{$v['naname']}}</td>
					<td>
						<select name="spec[{{$v['nature_nid']}}][value][]" id="">
							{{foreach from="$v['nazhi']" value="$vv"}}
							<option value="{{$vv}}" {{if value="$vv==$v['nazhi']"}}selected{{endif}}>{{$vv}}</option>
							{{endforeach}}
						</select>
					</td>
					<td>附加价格:
						<input type="text" name="spec[{{$v['nature_nid']}}][price][]" value="{{$v['shopprice']}}" />
					</td>
					<td><span class="btn btn-success add-spec">增加规格</span></td>
				</tr>
				{{endif}}
				{{endforeach}}
			</table>						
				<tr class="active">
					<td><a href="javascript:;" class="btn btn-sm btn-primary">列表图</a>	</td>
					<td colspan="6">
						<!-- html页面 -->
						<div lab="uploadFile">
						    <input id="f1" type="file" multiple="true">
						    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
						    <script type="text/javascript">
						        $(function() {
						            $('#f1').uploadify({
						                'formData'     : {//POST数据
						                    'hdcmsid' : 'vah7dtc9t6r26kq8en9434qv00',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : 'Public/uploadify/uploadify.swf',
						                'uploader' : "{{U('upload')}}",
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 1,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
						                    //转为json
						                    data=$.parseJSON(data);
						                    //获得图片地址
						                    var imageUrl = data.url;
						                    var li="<li style='float:left;list-style:none;'><img width='100' height='50' src='"+imageUrl+"'/><input type='hidden' name='listing' value='"+data.path+"'/></li>";
						                    $("#uploadList1 ul").prepend(li);
						                }
						            });
						            //点击关闭图片按钮
									$('.close_img').live('click',function(){
										$(this).parents('li').remove();
									})						            
						        });
						    </script>
						    <div id="uploadList1">
						        <ul>
									<!--如果有缩略图的时候-->
									{{if value="$olddata['listing']"}}
									<li style='display:inline-block;padding-left:10px'>
										<img style="width: 80px;height: 80px;" src="{{$olddata['listing']}}"/>
										<a href="javascript:;" class="close_img">X</a>
										<input type="hidden" name="listing" value="{{$olddata['listing']}}"/>
							    	</li>
									{{endif}} 						
						        </ul>
						    </div>
						</div>
					</td>
				</tr>
							<table class='table table-bordered'>
								<tr>
									<th colspan="3" class="btn btn-primary">
										商品图册
									</th>
								</tr>
								<tr class="info">
									<td>
										<!-- html页面 -->
										<div lab="uploadFile">
										    <input id="file" type="file" multiple="true">
										    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
										    <script type="text/javascript">
										        $(function() {
										            $('#file').uploadify({
										                'formData'     : {//POST数据
										                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
										                },
										                'fileTypeDesc' : '上传文件',//上传描述
										                'fileTypeExts' : '*.jpg;*.png',
										                'swf'      : './Public/uploadify/uploadify.swf',
										                'uploader' : "{{U('upload')}}",
										                'buttonText':'选择文件',
										                'fileSizeLimit' : '2000KB',
										                'uploadLimit' : 10,//上传文件数
										                'width':65,
										                'height':25,
										                'successTimeout':10,//等待服务器响应时间
										                'removeTimeout' : 0.2,//成功显示时间
										                'onUploadSuccess' : function(file, data, response) {
															//转为json
										                    data=$.parseJSON(data);
										                    //获得图片地址
										                    var imageUrl = data.url;
										                    var li="<li style='float:left;list-style:none;'><img width='100' height='50' src='"+imageUrl+"'/><input type='hidden' name='bigdrawing[]' value='"+data.path+"'/></li>";
										                    $("#uploadList ul").prepend(li);
										                }
										            });
						            //点击关闭图片按钮
									$('.close_img').live('click',function(){
										$(this).parents('li').remove();
									})										            
										        });
										    </script>
										    <div id="uploadList">
						    	 <ul>
									{{foreach from="$DetailData['bigdrawing']" value="$v"}}
									<li style='display:inline-block;padding-left:10px'>
										<img style='width:80px;height:80px' src="{{$v}}"/>
										<a href="javascript:;" class="close_img">X</a>
										<input type="hidden" name="bigdrawing[]" value="{{$v}}"/>
									</li>
									{{endforeach}}
						        </ul>
										    </div>
										</div>										
									</td>
								</tr>
							</table>
							<table class='table'>
								<tr class="next_show">
									<th class="btn btn-primary">
										<a style="color: white" href="">
											商品详细
										</a>
									</th>
								</tr>
								<tr class="table">
									<!--调用百度编辑器-->
									<script id="editor" type="text/plain" style="width:100%;height:140px;" name="goodsdetail">
									{{$pdata['goodsdetail']}}
									</script>
									<script>var ue = UE.getEditor('editor');</script>
								</tr>
							</table>
							<table class='table'>
								<tr class="next_show">
									<th class="btn btn-primary">
										<a style="color: white;" href="">
											售后服务
										</a>
									</th>
								</tr>
								<tr>
									<!--调用百度编辑器-->
									<script id="editor1" type="text/plain" style="width:100%;height:140px;" name="aftersale">
									{{$pdata['aftersale']}}
									</script>
									<script>var ue = UE.getEditor('editor1');</script>
								</tr>
							</table>
							<input type="hidden" name='tid' value='0'/>
							<input type="hidden" name="gid" id="" value="{{Q('get.gid')}}" />
							<input type="submit" value="确认修改" class="btn btn-primary btn-block btn-large" />
						</fieldset>
					</form>
				</div>
			</div>
		</div>
	</body>
</html>